Welcome![Sign In][Sign Up]
Location:
Search - applet html

Search list

[Internet-Network用Java编写HTML文件分析程序

Description:

Java编写HTML文件分析程序

 一、概述

    

    Web服务器的核心是对Html文件中的各标记(Tag)作出正确的分析,一种编程语言的解释程序也是对源文件中的保留字进行分析再做解释的。实际应用中,我们也经常会碰到需要对某一特定类型文件进行要害字分析的情况,比如,需要将某个HTML文件下载并同时下载与之相关的.gif.class等文件,此时就要求对HTML文件中的标记进行分离,找出所需的文件名及目录。在Java出现以前,类似工作需要对文件中的每个字符进行分析,从中找出所需部分,不仅编程量大,且易出错。笔者在近期的项目中利用Java的输入流类StreamTokenizer进行HTML文件的分析,效果较好。在此,我们要实现从已知的Web页面下载HTML文件,对其进行分析后,下载该页面中包含的HTML文件(假如在Frame中)、图像文件和ClassJava Applet)文件。

    

    二、StreamTokenizer

    

    StreamTokenizer即令牌化输入流的作用是将一个输入流中变成令牌流。令牌流中的令牌实体有三类:单词(即多字符令牌)、单字符令牌和空白(包括JavaC/C++中的说明语句)。

    

    StreamTokenizer类的构造器为: StreamTokenizer(InputStream in)

    

    该类有一些公有实例变量:ttypesvalnval ,分别表示令牌类型、当前字符串值和当前数字值。当我们需要取得令牌(即HTML中的标记)之间的字符时,应访问变量sval。而读向下一个令牌的方法是调用nextToken()。方法nextToken()的返回值是int型,共有四种可能的返回:

    

    StreamTokenizer.TT_NUMBER: 表示读到的令牌是数字,数字的值是double型,可以从实例变量nval中读取。

    

    StreamTokenizer.TT_Word: 表示读到的令牌是非数字的单词(其他字符也在其中),单词可以从实例变量sval中读取。

    

    StreamTokenizer.TT_EOL: 表示读到的令牌是行结束符。

    

    假如已读到流的尽头,则nextToken()返回TT_EOF

    

    开始调用nextToken()之前,要设置输入流的语法表,以便使分析器辨识不同的字符。WhitespaceChars(int low, int hi)方法定义没有意义的字符的范围。WordChars(int low, int hi)方法定义构造单词的字符范围。

    

    三、程序实现

    

    1HtmlTokenizer类的实现

    

    对某个令牌流进行分析之前,首先应对该令牌流的语法表进行设置,在本例中,即是让程序分出哪个单词是HTML的标记。下面给出针对我们需要的HTML标记的令牌流类定义,它是StreamTokenizer的子类:

    

    

    import java.io.*;

    import java.lang.String;

    class HtmlTokenizer extends

    StreamTokenizer {

    //定义各标记,这里的标记仅是本例中必须的,

    可根据需要自行扩充

     static int HTML_TEXT=-1;

     static int HTML_UNKNOWN=-2;

     static int HTML_EOF=-3;

     static int HTML_IMAGE=-4;

     static int HTML_FRAME=-5;

     static int HTML_BACKGROUND=-6;

     static int HTML_APPLET=-7;

    

    boolean outsideTag=true; //判定是否在标记之中

    

     //构造器,定义该令牌流的语法表。

     public HtmlTokenizer(BufferedReader r) {

    super(r);

    this.resetSyntax(); //重置语法表

    this.wordChars(0,255); //令牌范围为全部字符

    this.ordinaryChar('< '); //HTML标记两边的分割符

    this.ordinaryChar('>');

     } //end of constrUCtor

    

     public int nextHtml(){

    int token; //令牌

    try{

    switch(token=this.nextToken()){

    case StreamTokenizer.TT_EOF:

    //假如已读到流的尽头,则返回TT_EOF

    return HTML_EOF;

    case '< ': //进入标记字段

    outsideTag=false;

    return nextHtml();

    case '>': //出标记字段

    outsideTag=true;

    return nextHtml();

    case StreamTokenizer.TT_WORD:

    //若当前令牌为单词,判定是哪个标记

    if (allWhite(sval))

     return nextHtml(); //过滤其中空格

    else if(sval.toUpperCase().indexOf("FRAME")

    !=-1 && !outsideTag) //标记FRAME

     return HTML_FRAME;

    else if(sval.toUpperCase().indexOf("IMG")

    !=-1 && !outsideTag) //标记IMG

     return HTML_IMAGE;

    else if(sval.toUpperCase().indexOf("BACKGROUND")

    !=-1 && !outsideTag) //标记BACKGROUND

     return HTML_BACKGROUND;

    else if(sval.toUpperCase().indexOf("APPLET")

    !=-1 && !outsideTag) //标记APPLET

     return HTML_APPLET;

    default:

    System.out.println ("Unknown tag: "+token);

    return HTML_UNKNOWN;

     } //end of case

    }catch(IOException e){

    System.out.println("Error:"+e.getMessage());}

    return HTML_UNKNOWN;

     } //end of nextHtml

    

    protected boolean allWhite(String s){//过滤所有空格

    //实现略

     }// end of allWhite

    

    } //end of class

    

    以上方法在近期项目中测试通过,操作系统为Windows NT4,编程工具使用Inprise Jbuilder3


Platform: | Size: 1066 | Author: tiberxu | Hits:

[Streaming Mpeg4mfmpeg_1.documentation.html

Description: MediaFrame是一个开源的Java流媒体平台.它提供一个快速,容易实现的并且非常小的applet用来观看audio/video内容而不需要依赖其它播放程序或插件.MediaFrame支持Mpeg(Mpeg-1 & Mpeg-4)图象压缩工业标准,包括支持AAC与MP3. -MediaFrame is an open-source Java platform for streaming media. It provides a fast, be easy to achieve and very small applet to view audio / video content without the need to rely on Other player or plug-in. MediaFrame support Mpeg (Mpeg-1
Platform: | Size: 398679 | Author: liquan | Hits:

[JSP/Java一个简单的HTML浏览器

Description: Applet与Swing编写一个简单的HTML浏览器,是一个学习的好列程-Applet and prepared a simple HTML browser, a study is a good way out
Platform: | Size: 16355 | Author: 潜龙 | Hits:

[Other Games基于applet的java3D的魔方小程序

Description: 一个能用鼠标进行控制的小魔方。 编写html代码进行加载。
Platform: | Size: 4090 | Author: yimian | Hits:

[Other Web Codexdav.zip

Description: html 编辑器,属于WEB的,很好用
Platform: | Size: 1899014 | Author: my80888 | Hits:

[JSP/Javacolorpicker

Description: 很不错的一个获取html色彩值的Applet-a very good access to html color value of the Applet
Platform: | Size: 8192 | Author: 黄谱 | Hits:

[Multimedia programClipControl123

Description: 声音播放Java小程序 [程序语言] IE3, IE4, IE5, NS3, NS4+ [下载源程序] 立即下载 [源码来源] http://javaboutique.internet.com/ClipControl/ [功能描述] 这是个简单的录音剪辑播放小程序,可以进行一次播放和反复播放。 用法:把ClipControl.class (和conjunction.au声音文件) 放到你的HTML目录中。 HTML文档内容: <applet code="ClipControl.class" width=260 height=40> <param name=clip value="conjunction.au"> <param name=bgcolor value="#ffffff"> <param name=fgcolor value="#000000"> <param name=oninit value="load"> <param name=onstart value="play"> <param name=noplay value="false"> <param name=noloop value="false"> <param name=nostop value="false"> <param name=noload value="false"> <param name=boxplay value="false"> <param name=boxloop value="false"> <param name=boxstop value="false"> </applet>-voice broadcast Java programs [programming language] IE3, IE4, Internet Explorer 5, NS3, NS4 [Download source] download [Source sources] http://javaboutique.internet.com/ClipControl/ [Description] This is a simple audio clips players small programs, a broadcast and broadcast repeatedly. Usage : put ClipControl.class (conjunction.au sound files) into your HTML directory. HTML document : lt; Applet code = "ClipControl.class" width = 260 height = 40gt; Lt; Param clip name = value = "conjunction.au" gt; Lt; Param name = value bgcolor = "# ffffff" gt; lt; param fgcolor name = value = "# 000000" gt; lt; param oninit name = value = "load" gt; lt; param onstart name = value = "play" gt; lt; param noplay name = value = "false "gt
Platform: | Size: 72704 | Author: 沙雨 | Hits:

[JSP/Java一个简单的HTML浏览器

Description: Applet与Swing编写一个简单的HTML浏览器,是一个学习的好列程-Applet and prepared a simple HTML browser, a study is a good way out
Platform: | Size: 16384 | Author: 潜龙 | Hits:

[Chess Poker gamesgjb-wzq

Description: 用java编写的围棋程序,该程序是java applet编写,请编译后用html嵌入编译好的该类-prepared with the Go program, which is a java applet prepared, compiled using html embedded compiler such good
Platform: | Size: 4096 | Author: gjb | Hits:

[Button controlJavaButtonMakerSetup

Description: 如何做JAVA的BUTTON Magic Button creates Java applet buttons for the Web without requiring any Java or HTML programming. The program can create several buttons on one applet (even one on top of another), which can also include images and text labels for all three states: up, mouse-over, and down. You can also attach sounds to your buttons using the Wav2Au program (available as separate download), which converts WAV files to AU files. You can change button colors, position elements on the screen, set the height and width of objects, add links and target URLs, adjust the font, and more. Magic Button is flexible and easy to use and can produce highly professional results. You can find tutorials and live examples here: http://www.emu8086.com/wb/-JAVA BUTTON Magic Button creates Java applet buttons for the Web without requiring any Java or HTML programming. The program can create several buttons on one applet (even one on top of another), which can also include images and text labels for all three states : up, the mouse-over, and down. You can also attach sounds to your buttons using the Wav2Au program (available as separate download), which converts files to WAV files AU. You can change button colors, position elements on the screen , set the height and width of objects, add links and target URLs, adjust the font, and more. Magic Button is flexible and easy to use and can produce highly professional results. You can find tutorials and live examples here : http:// www.emu8086.com/wb/
Platform: | Size: 1610752 | Author: cyy | Hits:

[JSPsrJSP

Description: 讲述了怎样利用J5P构建完整的虚拟网站的全部技术与过程。全书共分为五个部分:第一部分是相关知识,包括JsP起源与构建JsP环境。第二部分是支持技术,包括HTML与DreMweaver。第三部分是继承者,包括指南、Java基础、JSP基本语法、servlet及其API、内部对象、JSP container、JsP核心API。第四部分是集成者.包括JDBC、JavaBeans、Applet、XML。第五部分是综合应用。-described how the use of J5P builds a complete virtual sites all the skills and processes. The book is divided into five parts : the first part is related knowledge, including the origin and Construction JsP JsP environment. The second part of the support technologies, including HTML and DreMweaver. The third part of the succession, including guidelines, based on Java, JSP basic grammar, and servlet API. internal targets, JSP container, JsP core API. The fourth part of the integrator. Including JDBC, JavaBeans, Applet, XML. The fifth part of the comprehensive application.
Platform: | Size: 7860224 | Author: 沈利 | Hits:

[Internet-Network28160302278

Description: 1.签写留言:可以选择头像,头像分男性、女性和中性。可以填写个人主页、邮箱和QQ号码。留言可以在后台设定留言文字的数量,可以设定文字的颜色、大小、加粗、斜体。支持HTML代码编辑。 2.悄悄话功能:留言可以选择悄悄话功能,只能管理员查看,其它人看不到。可以设定回复查看代码(可不填)回复查看码用于以后查看管理员对悄悄话的回复,若不填,管理员将无法回复您的悄悄话。 3.留言搜索:搜索范围将包括:留言者的称呼、留言标题、正文以及回复。 4.留言公告:可以在本网奇留言本内添加站内留言公告,公告可以在后台编辑删除,公告向上滚动显示。 5.最新回复:可以显示最新回复的留言8条,点击标题可以看到留言内容和回复内容。 -1. Sign message : choose a portrait-men, women and neutral. Fill it personal home page, mail and QQ numbers. Messages can be set in the background of the number of text messages that can set the text color, size, Bold, italics. Support for HTML editors. 2. ABC functions : voice whispered can choose functions, administrators can view, other people do not see. View could set back code (optional) check back yards for administrators to look after the whispered reply, if not filled, administrators will not be able to respond to your brother. 3. Search message : the scope of the search will include : voice of the call, voice mail headers, body and back. 4. Messages Notice : Kellet said in the message within the message added stations Notice, notice can be edited to delete in the background, show
Platform: | Size: 640000 | Author: 姚紫欣 | Hits:

[JSPwebstart

Description: 系统运行时的截屏图:webstart_screen01.gif/webstart_screen02.gif。 安装使用前,请先查阅:help/help.html。 本系统的客户端浏览器仅支持IE6.0,其他浏览器如MyIE2/FireFox不能正确运行Java Applet或JScript,故无法正常使用本系统。特此说明-system running at the screen shots : webstart_screen01.gif/webstart_screen02.gif. Before the installation, inspection post : help/help.html. The system of the client browser supports only Internet Explorer 6.0, other browsers such as MyIE2/FireFox can not correctly run Java applet or JScript, it is impossible to normal use of the system. Hua
Platform: | Size: 433152 | Author: signme | Hits:

[Streaming Mpeg4mfmpeg_1.documentation.html

Description: MediaFrame是一个开源的Java流媒体平台.它提供一个快速,容易实现的并且非常小的applet用来观看audio/video内容而不需要依赖其它播放程序或插件.MediaFrame支持Mpeg(Mpeg-1 & Mpeg-4)图象压缩工业标准,包括支持AAC与MP3. -MediaFrame is an open-source Java platform for streaming media. It provides a fast, be easy to achieve and very small applet to view audio/video content without the need to rely on Other player or plug-in. MediaFrame support Mpeg (Mpeg-1
Platform: | Size: 398336 | Author: liquan | Hits:

[Game Programabsolutespace

Description: 一个射击类的小游戏,运用java applet编译,解压缩后运行index.html即可进行游戏。-a small game, using java applet compiler, decompress after running index.html can play games.
Platform: | Size: 57344 | Author: peng xu | Hits:

[Picture ViewerMultiImageViewer

Description: This applet demonstrates:1、receiving multiple files from a drag-drop operation 2、being a drag-drop source 3、optimizing the viewer for performance--creating thumbnails on the fly and owner draw issues 4、usability issues--changing image and form sizes and utilizing a non-paging scrollbar -This applet demonstrates : 1. receiving multiple files from a drag-drop oper.html ation 2, being a drag-drop source 3, optimizing performance for the viewer-- creat ing thumbnails on the fly and owner draw four issues , usability issues-- changing image and form sizes and utilizing a non-paging 9x15
Platform: | Size: 10240 | Author: 田巾 | Hits:

[CSharp1

Description: 将aspx页面生成对应html页面的小程序,业余制作,初学者可以-Aspx page to generate the corresponding applet html page, amateur production, beginners can
Platform: | Size: 3072 | Author: lllever | Hits:

[WEB CodeValveMap

Description: applet+servlet+.html实现动态描点功能,可以从页面向applet进行传参.-applet+ servlet+. html dynamic depiction point functions, can be carried out from the page to the applet parameter Chuan.
Platform: | Size: 665600 | Author: 石岩 | Hits:

[VC/MFCjavaapplet

Description: Java Applet 入门(HTML) 软件大小:384KB 运行环境:HTML -Java Applet Introduction (HTML) Software size: 384KB Operating Environment: HTML
Platform: | Size: 393216 | Author: weiming | Hits:

[JSP/Javaapplet

Description: HTML Editor with java.
Platform: | Size: 68608 | Author: Adasda | Hits:
« 12 3 4 5 6 7 8 »

CodeBus www.codebus.net